﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace TermitesMagnets
{
    class Level3 : Level
    {
        private static int numberOfColors = 3;
        private const int numberOfTermitesPerColor = 400;

        public Level3(GameplayScreen game)
            : base(game)
        {
        }

        public override void Restart()
        {

            base.Restart();
            board = new Board();
            colors = new List<Color>() { Color.Red, Color.Green, Color.Blue, Color.Yellow };
            magnetsColors = new List<Color>() { Color.IndianRed, Color.LightGreen, Color.LightBlue, Color.LightYellow };
            targets = new List<TargetRect>();
            HumanTargets.Add(new TargetRect(this, Color.Red, 0,
                (int)(numberOfTermitesPerColor), new Vector2(20, 20), new Vector2(2, 2)));

            AiTargets.Add(new TargetRect(this, Color.Green, 1,
                (int)(numberOfTermitesPerColor), new Vector2(350, 20), new Vector2(TargetRect.rectangleEdge, 0)));
            AiTargets.Add(new TargetRect(this, Color.Blue, 2,
                (int)(numberOfTermitesPerColor), new Vector2(20, 220), new Vector2(0, TargetRect.rectangleEdge)));

            targets.AddRange(AiTargets);
            targets.AddRange(HumanTargets);

            termites = new List<Termite>();

            for (int i = 0; i < numberOfColors; i++)
            {
                for (int j = 0; j < numberOfTermitesPerColor; j++)
                {
                    int col, row;
                    do
                    {
                        col = Game1.Rand.Next(Board.Cols);
                        row = Game1.Rand.Next(Board.Rows);
                    } while (!board.Occupy(col, row));
                    Vector2 position = new Vector2(col, row);
                    termites.Add(new Termite(Game1.GlobalGame, this, position, colors[i], i));
                }
            }

            magnets = new List<Magnet>();
            for (int i = 0; i < numberOfColors; i++)
            {
                Vector2 position = new Vector2(Game1.Rand.Next(Board.Cols), Game1.Rand.Next(Board.Rows));
                magnets.Add(new Magnet(Game1.GlobalGame, this, position, magnetsColors[i], i));

                if (i > 0)
                {
                    magnets[i].IsAI = true;
                    magnets[i].Ai.setParameters(magnets[i], ref this.termites, ref this.targets, ref this.magnets);
                }
            }


            pwus = new List<Pwu>();
            for (int i = 0; i < numberOfColors / 2; i++)
            {
                Vector2 position = new Vector2(Game1.Rand.Next(Board.Cols), Game1.Rand.Next(Board.Rows));
                pwus.Add(new Pwu0(Game1.GlobalGame, this, position, 0));

                //Vector2 position1 = new Vector2(Game1.Rand.Next(Board.Cols), Game1.Rand.Next(Board.Rows));
                //pwus.Add(new Pwu1(Game1.GlobalGame, this, position1, 0));
            }

        }
    }
}
